var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post('/', function(req, res, next) {
  console.log(req.body);
  let id = req.body.id;
  console.log('id: ', id);
  let method = req.body.method;
  console.log('method: ', method);
  if(method === 'status') {
      res.send({
    jsonrpc: '2.0',
  id: req.body.id,
  result: {
    node_info: {
      protocol_version:{p2p:'8',block:'11',app:'0'},
      id: '83b19b931e649e52799007fff186b8bd31b8dfb1',
      listen_addr: 'tcp://0.0.0.0:50910',
      network: 'kava_2222-10',
      version: '0.37.13',
      channels: '40202122233038606100',
      moniker: 'kava_mainnet_archive_1',
      other:{tx_index:"on",rpc_address:"tcp://0.0.0.0:50913"}
    },
    sync_info: {
      latest_block_hash: '2CCCB68C6F36F672F9454F18BAA21DC27B31146640CBC150E04F3A6476DABA46',
      latest_app_hash: '039A04CEC8A58D12F5720249AC45CAEF2BB06038B30B21062405BACBA3635819',
      latest_block_height: '15956582',
      latest_block_time: '2025-06-30T02:07:22.166788694Z',
      earliest_block_hash: '9D2AF876309BB9174604004A813DCFEE94F4947B08C5BB4C1A042F318488851E',
      earliest_app_hash: 'E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855',
      earliest_block_height: '1',
      earliest_block_time: '2022-05-25T17:00:00Z',
      catching_up: false
    },
    validator_info: {
      address: 'F5CB895001D65C9A9855B2F86F5105E859AC3E23',
      pub_key: {type:"tendermint/PubKeyEd25519",value:"AMIaveVKsDUHPPUA4Pn/qiLjsiA8HaSqQBoSQv9n0nw="},
      voting_power: '0'
    }
  }
  });
  }else if(method === 'block') {
    let data ={
  jsonrpc: '2.0',
  id: id,
  result: {
    block_id: {
      hash: '2CCCB68C6F36F672F9454F18BAA21DC27B31146640CBC150E04F3A6476DABA46',
      parts: {"total":1,"hash":"A57E5043781635D43ACB8A036E416F0E79DA5CB70C6AEE7268932F8C8DD7C887"}}
    },
    block: {
      header: {
      data: [Object],
      evidence: [Object],
      last_commit: [Object]
    }
  }
}


    res.send(data);
  }else if(method === 'tx_search') {

  }

});

module.exports = router;
